From 5cb542c8217bbe2fc05c3959aa23c850880fbc40 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Aug 2014 20:54:32 -0700 Subject: [PATCH] Lift the requirement that cargo is built with make Cargo should be able to build with cargo so others can depend on the cargo library. This means that the one requirement of the CFG_VERSION env var will not be available. This alters `version()` to prioritize CFG_VERSION but fall back to the cargo-specified variables. --- src/cargo/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index f80f38d2e..89baab021 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -200,7 +200,14 @@ fn handle_cause(err: &CargoError, shell: &mut MultiShell) { } pub fn version() -> String { - format!("cargo {}", env!("CFG_VERSION")) + format!("cargo {}", match option_env!("CFG_VERSION") { + Some(s) => s.to_string(), + None => format!("{}.{}.{}{}", + env!("CARGO_PKG_VERSION_MAJOR"), + env!("CARGO_PKG_VERSION_MINOR"), + env!("CARGO_PKG_VERSION_PATCH"), + option_env!("CARGO_PKG_VERSION_PRE").unwrap_or("")) + }) } fn flags_from_args(args: &[String], -- 2.30.2